# -*- coding: utf-8 -*-

import pandas as pd
import numpy as np
from pandas import Series, DataFrame

s1 = Series([1, 3, 5, 7], index=['A', 'B', 'C', 'D'])
print(s1)

# 添加index, 并填充值
print(s1.reindex(index=['A', 'B', 'E', 'C', 'D'], fill_value=9))

df = DataFrame(np.random.random(25).reshape([5, 5]), index=['A', 'B', 'D', 'E', 'F'],
               columns=['c1', 'c2', 'c3', 'c4', 'c5'])

# 增加 C 行 和 c6 列
print(df.reindex(index=['A', 'B', 'C', 'D', 'E', 'F'], columns=['c1', 'c2', 'c3', 'c4', 'c5', 'c6']))

# 保留指定行和列
print(df.reindex(index=['A', 'B'], columns=['c1', 'c2']))

# 直接删除指定列
print(df.drop(columns='c3'))

# 直接在原数据上删除
df.drop('c1', axis=1, inplace=True)
print(df)
